package com.NeuglsWorkStudio.Utility
{
	public class TFunctionManager
	{
		public var OBJ:Object;
		
		public function TFunctionManager()
		{
			this.OBJ = new Object();
		}
		
		/**
		 * 注册一个function
		 * @param func
		 * 
		 */        
		public function regFunction(ID:String,func:Function):void{
			if(func==null){
				return;
			}
			if(!OBJ[ID]) OBJ[ID]=[];
			if(OBJ[ID].indexOf(func)==-1){
				OBJ[ID].push(func);
			}
		}
		/**
		 *移除一个function 
		 * @param func
		 * 
		 */        
		public function removeFunction(ID:String,func:Function):void{
			if(!OBJ[ID]) return;
			var i:int = OBJ[ID].indexOf(func);
			if(i>=0){
				OBJ[ID].splice(i,1);
			}
		}
		/**
		 * 执行！ 
		 * @param arg
		 * 
		 */        
		public function doFunction(ID:String,arg:Array=null):void{
			if(!OBJ[ID]) return;
			for each(var f:Function in OBJ[ID]){
				f.apply(this,arg);
			}
		}
		
		
		/**返回Index指定的函数*/
		public function getFunction(ID:String,Index:int=0):Function{
			if(!OBJ[ID]) return null;
			return OBJ[ID][Index];
		}
	}
}